/**
 *
 */
package com.wedroid.r2d2.dao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericJdbcSupport;
import com.wedroid.entity.command.Command;

/**
 * @author lute
 */
@Repository
public class CommandDaoSupport {

    @Autowired
    private GenericJdbcSupport genericJdbcSupport;

    /**
     * @param contacterId
     * @param keyword
     * @return
     */
    public Command getExclusiveCommand(Long contacterId, String keyword) {
        String sentence = "SELECT id AS id, keyword AS keyword, template AS template, template_type AS template_type, alias AS alias, contacter_id AS 'contacter.id' FROM command WHERE contacter_id = :id AND (keyword = :keyword or alias = :keyword)";

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("id", contacterId);
        parameters.put("keyword", keyword);

        return genericJdbcSupport.queryForObject(sentence, parameters, Command.class);
    }

    /**
     * @param keyword
     * @return
     */
    public Command getGeneralCommand(String keyword) {
        String sentence = "SELECT id AS id, keyword AS keyword, template AS template, template_type AS template_type, alias AS alias, contacter_id AS 'contacter.id' FROM command WHERE contacter_id is NULL AND (keyword = :keyword or alias = :keyword)";
        return genericJdbcSupport.queryForObject(sentence, "keyword", keyword, Command.class);
    }

}
